package com.common.www.bean.entity.auth;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.springframework.boot.base.jpa.domain.annotations.QueryCacheable;
import org.springframework.boot.base.jpa.domain.entity.NumberIdentityEntity;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * 角色实体类
 *
 * @author cWX183898
 */
@DynamicUpdate(true)
@DynamicInsert(true)
@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@QueryCacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Table(name = "auth_role", uniqueConstraints = {@UniqueConstraint(columnNames = "name")})
public class AuthRole extends NumberIdentityEntity {
    private static final long serialVersionUID = 2343635839703216816L;

    @Column(length = 64, nullable = false)
    private String name;

    @Column(length = 1024)
    private String description;

    @JsonIgnoreProperties(value = {"authRoles"})
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "auth_role_ref_access", joinColumns = @JoinColumn(name = "role_id"), inverseJoinColumns = @JoinColumn(name = "access_id"))
    private List<AuthAccess> authAccesses = new ArrayList<AuthAccess>(0);

    @JsonIgnoreProperties(value = {"authRoles", "organization", "position"})
    @ApiModelProperty(value = "app不用")
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "auth_user_ref_role", joinColumns = @JoinColumn(name = "role_id"), inverseJoinColumns = @JoinColumn(name = "user_id"))
    private List<AuthUser> authUsers = new ArrayList<AuthUser>(0);


}
